package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class Adressebog here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Adressebog
{
    // instance variables - replace the example below with your own
    private ArrayList<Person> p;
    private static Adressebog instance;
    /**
     * Constructor for objects of class Adressebog
     */
    private Adressebog()
    {
        p = new ArrayList<Person>();
    }
    
    //Singleton
    public static Adressebog getInstance()
    {
        if(instance == null)
        {
            instance = new Adressebog();
        }
        return instance;
    }

    /**
     * An example of a method - replace this comment with your own
     * 
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y 
     */
    public void addPerson(Person person)
    {
        p.add(person);
    }
    
    public void sletPerson(Person person)
    {
        p.remove(person);
    }
    
    public Person findPerson(int id)
    {
    for (int i=0; i<this.p.size(); i++)
    {
        Person person = this.p.get(i);
        if (person.getId() == id)
        {
             return person;
        }
    }   
    return null; // no Customer found with this ID; maybe throw an exception
   }
   
}
























